{ Класс формы заявления для приложения создания заявлений на стороне заявителя requestCreator


  Module is a part of project http://code.google.com/p/drivers-training-request
  Copyright (C) 2012 Leonid Vlasov leoniv@bk.ru

  This source is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.

  This code is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.

  A copy of the GNU General Public License is available on the World Wide Web
  at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
  to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  MA 02111-1307, USA.
}

unit RequestFormCreator;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, genericrequestform,uuid,commonetypes,StdCtrls,Dialogs,MaskEdit,Controls,Forms,AboutFrm,ConsoleFrm;
type

  { TCreateReqForm }

  TCreateReqForm = Class(TGReqForm)
    btOpen:TButton;
    btSave:TButton;
    btSaveAs:TButton;
    btExit:TButton;
    btAbout:TButton;
    procedure FormCreate(Sender: TObject);
    procedure onClickExit(Sender:TObject);
    procedure onClickSave(Sender:TObject);
    procedure onClickSaveAs(Sender:TObject);
    procedure onClickOpen(Sender:TObject);
    procedure onClickAbout(Sender:TObject);
    procedure ShowError(Mess:String);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); Override;
    public
          TableTichers:TTableDesc;

  end;
var
  ReqCreatorMain:TCreateReqForm;
implementation

{ TCreateReqForm }

procedure TCreateReqForm.FormCreate(Sender: TObject);
begin
  Inherited FormCreate(Sender);
  Modifaed:=false;
  SetCaption(strNew);
  AddButton(btSaveAs,strSaveAs,@onClickSaveAs);
  AddButton(btSave,strSave,@onClickSave);
  AddButton(btOpen,strOpen,@onClickOpen);
  AddButton(btExit,strExit,@onClickExit);
  AddButton(btAbout,strAbout,@onClickAbout,'',alLeft);

  //Иницируем grids
  //TableTichers:=TTableDesc.Create();
  //TableTichers.Add(@tblfFirstname);
  //TableTichers.Grid:=Tichers;
end;

procedure TCreateReqForm.onClickExit(Sender: TObject);
begin
  {TODO  -o: -c: : Реализовать метод TCreateReqForm.onClickExit }
  Close;
end;

procedure TCreateReqForm.onClickSave(Sender: TObject);
var
  SaveDialog:TSaveDialog;
  Report:TMessagesArray;
begin
  //if FFileName='' then
  //begin
  //  onClickSaveAs(Sender);
  //  Exit;
  //end;
  if Not CheckObjectFullData(Report) then
  begin
    ShowErrorReport(Report,Format(flCreatorDataIsNotFull,[opCreatorSaveToFile]));
    Exit;
  end;
  if Not CheckObjectCorrectData(Report) then
  begin
    ShowErrorReport(Report,Format(flCreatorDataINotCorrect,[opCreatorSaveToFile]));
    Exit;
  end;
 if (FFileName='') or (Sender=btSaveAs) then
   begin
     SaveDialog:=TSaveDialog.Create(ReqCreatorMain);
     SaveDialog.Filter:=dlgoFileFilter;
     SaveDialog.FilterIndex := 1;
     //SaveDialog.InitialDir:=Get;
     SaveDialog.Options:=[ofOverwritePrompt];
     SaveDialog.FileName:=commonetypes.GetDefaultFileName(groupNumber.Text);
     if SaveDialog.Execute then
       if NOT SaveToXML(Report,SaveDialog.FileName) then
         ShowErrorReport(Report,Format(flCreatorIOError,[opCreatorSaveToFile]));
     SaveDialog.Free;
   end
  else
   if NOT SaveToXML(Report,FFileName) then
     ShowErrorReport(Report,Format(flCreatorIOError,[opCreatorSaveToFile]));
end;

procedure TCreateReqForm.onClickSaveAs(Sender: TObject);
//var
//  SaveDialog:TSaveDialog;
//  Report:TMessagesArray;
//  Mess:String;
begin
  onClickSave(Sender);
  ////commonetypes.isEmtyStr(TMaskEdit(Widget).Text);
  //if Not CheckObjectFullData(Report) then
  //begin
  //  ShowErrorReport(Report);
  //  Exit;
  //end;
  //if Not CheckObjectCorrectData(Report) then
  //begin
  //  ShowErrorReport(Report);
  //  Exit;
  //end;
  //SaveDialog:=TSaveDialog.Create(ReqCreatorMain);
  //SaveDialog.Filter:=dlgoFileFilter;
  //SaveDialog.FilterIndex := 1;
  ////SaveDialog.InitialDir:=Get;
  //SaveDialog.Options:=[ofOverwritePrompt];
  //SaveDialog.FileName:=commonetypes.GetDefaultFileName(groupNumber.Text);
  //if SaveDialog.Execute then
  //  if NOT SaveToXML(Mess,SaveDialog.FileName) then
  //    ShowError(Mess);
  //SaveDialog.Free;
end;

procedure TCreateReqForm.onClickOpen(Sender: TObject);
var
  OpenDialog:TOpenDialog;
  Report:TMessagesArray;
begin
  OpenDialog:=TOpenDialog.Create(ReqCreatorMain);
  OpenDialog.DefaultExt:=dlgoFileExt;
  OpenDialog.Filter:=dlgoFileFilter;
  OpenDialog.FilterIndex:=1;
  //OpenDialog.InitialDir:=GetCurrentDir;
  if OpenDialog.Execute then
    begin
       if Not ReadFromXML(Report,OpenDialog.FileName) then
         ShowErrorReport(Report,Format(flCreatorIOError,[opCreatorReadFromFile]));
    end;
  OpenDialog.Free;
end;

procedure TCreateReqForm.onClickAbout(Sender: TObject);
var
  AboutDialog:TAboutForm;
begin
  AboutForm:=TAboutForm.Create(ReqCreatorMain);
  { TODO -oleo : Реализовать метод TCreateReqForm.onClickAbout}
  AboutForm.ShowModal;
  AboutForm.Free;
end;

procedure TCreateReqForm.ShowError(Mess: String);
begin
       ToConsole(Mess,msgError);
end;


procedure TCreateReqForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
  if Modifaed then
     CanClose:=(QuestOnExitWitoutSaving() = mrYes)
  else
      CanClose:=(QuestOnExit() = mrYes);
end;

end.
